package com.vpclub.service;

import com.vpclub.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author : leimingchao
 * @Description:
 * @date Date : 2021年06月07日 22:12
 */
@Service
public class BookService {
    @Autowired
    private BookDao bookDao;

    /**
     * 结账：传入哪个用户买了哪本书
     * @param username
     * @param isbn
     */
    @Transactional
    public void checkOut(String username,String isbn) {
        //1.减库存
        bookDao.updateStock(isbn);
        int price = bookDao.getPrice(isbn);
        //2.减余额
        bookDao.updateBalance(username,price);
    }
}
